package common

type ServiceInfo struct {
	ServiceType string
	ServiceId   string
}

type IMsgHandler interface {
	HandleMsg(msg Message, from ServiceInfo, connId string) error
}

type IMsgDispatcher interface {
	// 注册服务
	Register(service ServiceInfo, handler IMsgHandler) error

	// 注销服务
	Unregister(service ServiceInfo) error

	// 异步消息分发，不等待响应
	Dispatch(msg Message, from ServiceInfo, to ServiceInfo, connId string) error

	// 同步等待指定响应，如果超时则返回错误
	DispatchSync(
		msg Message,
		from ServiceInfo,
		to ServiceInfo,
		connId string,
		resCmd string,
	) (res *Message, err error)

	// 异步等待指定响应，超时自动构造超时响应消息
	DispatchWait(
		msg Message,
		from ServiceInfo,
		to ServiceInfo,
		connId string,
		resCmd string,
	) error
}
